package com.rao.gmall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rao.gmall.model.product.BaseCategory1;
import com.rao.gmall.model.product.BaseCategory2;
import com.rao.gmall.model.product.BaseCategory3;
import com.rao.gmall.model.vo.IndexCategoryVo;
import com.rao.gmall.product.mapper.BaseCategory1Mapper;
import com.rao.gmall.product.mapper.BaseCategory2Mapper;
import com.rao.gmall.product.mapper.BaseCategory3Mapper;
import com.rao.gmall.product.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author nzmxfan
 * @create 2021-07-31-19:49
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    BaseCategory1Mapper baseCategory1Mapper;

    @Resource
    BaseCategory2Mapper baseCategory2Mapper;

    @Resource
    BaseCategory3Mapper baseCategory3Mapper;

    @Override
    public List<BaseCategory1> getCategory1List() {

        return baseCategory1Mapper.selectList(null);
    }

    @Override
    public List<BaseCategory2> getCategory2List(Long category1Id) {

        QueryWrapper<BaseCategory2> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category1_id", category1Id);

        return baseCategory2Mapper.selectList(queryWrapper);
    }

    @Override
    public List<BaseCategory3> getCategory3List(Long category2Id) {

        QueryWrapper<BaseCategory3> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category2_id", category2Id);

        return baseCategory3Mapper.selectList(queryWrapper);
    }

    @Override
    public List<IndexCategoryVo> getAllCategorysForIndexHtml() {
        // 定义一个变量进行后自增，作为 IndexCategoryVo 的 index 属性值
        int index = 1;
        List<IndexCategoryVo> indexHtml = baseCategory3Mapper.getAllCategorysForIndexHtml();
        for (IndexCategoryVo indexCategoryVo : indexHtml) {
            indexCategoryVo.setIndex(index++);
        }
        return indexHtml;
    }

}
